#include "pm/manager.h"

using namespace pm;

//{ Shotcuts
bool pm::load(const wxString& dbname)
{
	return ManagerST::Get()->load(dbname);
}

bool pm::insert(db::Object& obj)
{
	return ManagerST::Get()->insert(obj);
}

bool pm::query(ICriteria& criteria)
{
	return ManagerST::Get()->query(criteria);
}

bool pm::select(ICriteria& criteria)
{
	return query(criteria);
}

bool pm::update(db::Object& obj)
{
	return ManagerST::Get()->update(obj);
}

//}

Manager::Manager()
{
}

Manager::~Manager()
{
}

bool Manager::is_db_open()
{
	return m_db.IsOpen();
}

bool Manager::load(const wxString& dbname)
{
	if (is_db_open()) {
		m_db.Close();
	}
	m_dbName.clear();
	
	m_db.Open(dbname);
	if (!is_db_open()) {
		return false;
	}
	init_db();
	m_dbName = dbname;
	return true;
}


bool Manager::insert(db::Object& obj)
{
	return is_db_open() && obj.insert(m_db);
}

bool Manager::query(ICriteria& criteria)
{
	return is_db_open() && criteria.query(m_db);
}

bool Manager::update(db::Object& obj)
{
	return is_db_open() && obj.update(m_db);
}
